package com.example.audiobooks.ranking.adapter;


import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.example.audiobooks.R;
import com.example.audiobooks.ranking.bean.ResultNewsBean;

import java.util.List;

public class NewsRecommendAdapter extends BaseAdapter {
    private final Context mContext;
    private final List<ResultNewsBean.ResultBean.RecommendInfoBean> datas;

    public NewsRecommendAdapter(Context mContext, List<ResultNewsBean.ResultBean.RecommendInfoBean> recommend_info){
        this.mContext = mContext;
        this.datas = recommend_info;
    }
    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView == null){
            convertView = View.inflate(mContext, R.layout.item_news_recommend_item,null);
            viewHolder = new ViewHolder();
            viewHolder.news_title = (TextView) convertView.findViewById(R.id.news_title);
            viewHolder.news_source =(TextView) convertView.findViewById(R.id.news_source);
            viewHolder.news_date = (TextView) convertView.findViewById(R.id.news_date);
            viewHolder.news_amount = (TextView) convertView.findViewById(R.id.news_amount);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder)convertView.getTag();
        }

        /*根据位置得到对应的数据,设置图片，标题，价格*/
        ResultNewsBean.ResultBean.RecommendInfoBean recommendInfoBean = datas.get(position);
        viewHolder.news_title.setText(recommendInfoBean.getNews_title());
        viewHolder.news_source.setText(recommendInfoBean.getNews_source());
        viewHolder.news_date.setText(recommendInfoBean.getNews_date());
        viewHolder.news_amount.setText(recommendInfoBean.getNews_amount());
              return convertView;
    }
    public static class ViewHolder{
        TextView news_title;
        TextView news_source;
        TextView news_date;
        TextView news_amount;
    }
}
